package com.dhcc.sds.base.controller;


import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;



import com.dhcc.sds.base.entity.SdsQcentityIndexEntity;
import com.dhcc.sds.base.service.ISdsQcentityIndexService;


/**
 * 病种指标配置表
 * 
 * @ClassName: SdsQcentityIndexController
 * @Description: TODO
 * @author sunyingjie
 * @date 2021-03-22 10:10:51
 */
@Controller
@RequestMapping("${sys.backendPath}/sds/sdsqcentityindex")
public class SdsQcentityIndexController extends BaseController {

	private String PREFIX = "/backend/sds/sdsqcentityindex/";

	@Autowired
	private ISdsQcentityIndexService sdsQcentityIndexService;
	

    /**
     * 跳转到病种指标配置表列表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "sdsqcentityindex.html";
    }
	
    /**
     * 跳转到新增病种指标配置表
     */
    @RequestMapping("/to_add")
    public String toAdd() {
        return PREFIX + "sdsqcentityindex_add.html";
    }
	
	/**
     * 跳转到修改病种指标配置表
     */
    @RequestMapping("/to_update/{sdsQcentityIndexId}")
    public String toUpdate(@PathVariable Long sdsQcentityIndexId, Model model) {
        SdsQcentityIndexEntity sdsQcentityIndex = this.sdsQcentityIndexService.selectById(sdsQcentityIndexId);
        model.addAttribute("sdsQcentityIndex",sdsQcentityIndex);
        return PREFIX + "sdsqcentityindex_edit.html";
    }

    /**
     * 获取病种指标配置表列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam Map<String, Object> params) {
		Page<SdsQcentityIndexEntity> page = new PageFactory<SdsQcentityIndexEntity>().defaultPage();
        List<SdsQcentityIndexEntity> result = this.sdsQcentityIndexService.page(page,params);
        page.setRecords((List<SdsQcentityIndexEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增病种指标配置表
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(SdsQcentityIndexEntity sdsQcentityIndex) {
        if (CommonUtil.isOneEmpty(sdsQcentityIndex)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        sdsQcentityIndex.insert();
        return R.ok();
    }

    /**
     * 删除病种指标配置表
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long sdsQcentityIndexId) {
	
        this.sdsQcentityIndexService.deleteById(sdsQcentityIndexId);

        return R.ok();
    }

    /**
     * 修改病种指标配置表
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SdsQcentityIndexEntity sdsQcentityIndex) {
        if (CommonUtil.isOneEmpty(sdsQcentityIndex)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        SdsQcentityIndexEntity old = this.sdsQcentityIndexService.selectById(sdsQcentityIndex.getId());

        old.setParref(sdsQcentityIndex.getParref());
        old.setIdxType(sdsQcentityIndex.getIdxType());
        old.setIdxCode(sdsQcentityIndex.getIdxCode());
        old.setIdxDesc(sdsQcentityIndex.getIdxDesc());
        old.setIndNo(sdsQcentityIndex.getIndNo());
        old.setIsActive(sdsQcentityIndex.getIsActive());
        old.updateAllColumnById();
        return R.ok();
    }
	
}
